using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;

using com.paypal.soap.api;
using IGlobalist.Cms.Model;

namespace IGlobalist.Cms.Common
{
    public class DataUtils
    {

        public static bool IsDataValid(object data, DataType type){
            switch (type)
            {
                case DataType.Integer:
                    try
                    {
                        long test = Convert.ToInt64(data);
                        return true;
                    }
                    catch
                    {
                        return false;
                    }
                    break;
            }
            return true;
        }


        public static string ScriptEscape(string str)
        {
            int n = 0;
            while ((n = str.IndexOf("'", n)) != -1)
            {
                str = str.Replace("'", "\\'");
                n = n + 2;
            }
            return str;
        }
        public static Table ExtPropertiesParser(PropertyList properties)
        {
            Table tb = new Table();
            foreach (IContentProperty property in properties){
                tb.Rows.Add(PropertyParser(property));
            }

            return tb;
        }

        private static TableRow PropertyParser(IContentProperty property)
        {
            TableRow tr = new TableRow();
            TableCell label = new TableCell();
            label.Text = property.DisplayName;
            tr.Cells.Add(label);
            TableCell cellControl = new TableCell();
            Cms.Admin.Control.CmsPropertyControl control= new Cms.Admin.Control.CmsPropertyControl((BaseProperty)property);
            cellControl.Controls.Add(control);
                tr.Cells.Add(cellControl);
            
            return tr;
        }

        private static Control GetControl(InputType inputType, object value)
        {
            Control control=null;
            switch (inputType)
            {
             
                case InputType.CheckBox:
                    control = new CheckBox();
                    ((CheckBox)control).Checked = Convert.ToBoolean(value);
                    break;
              
                case InputType.PasswordField:
                    control = new TextBox();

                    ((TextBox)control).TextMode = TextBoxMode.Password;
                    ((TextBox)control).Text = value.ToString();
                    break;
                case InputType.RadioButtonList:

                    break;
                case InputType.TextBox:
                    control = new TextBox();
                    ((TextBox)control).Text = value.ToString();
                    break;
                case InputType.TextBoxMultiLine:
                    control = new TextBox();
                    ((TextBox)control).TextMode = TextBoxMode.MultiLine;
                    ((TextBox)control).Text = value.ToString();
                    break;
             
                default:
                    control = new TextBox();
                    break;

            }
            return control;
        }

        public static bool IsSuccessfull(AckCodeType ack)
        {
            return ack == AckCodeType.Success || ack == AckCodeType.SuccessWithWarning;
        }
     
    }
}
